package alik.notes.client.event.impl;

import alik.notes.client.event.Events.NoteAddHandler;
import alik.notes.client.event.Events.NotesChangeEvent;
import alik.notes.client.gin.AppGinInjectorFactory;
import alik.notes.shared.data.Note;
import alik.notes.shared.service.NotesService;
import alik.notes.shared.service.NotesServiceAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class NoteAddHandlerImpl implements NoteAddHandler {

	@Override
	public void addNote(final Note note) {
		final NotesServiceAsync notesService = GWT.create(NotesService.class);
		notesService.addNote(note, new AsyncCallback<Void>() {
			@Override
			public void onSuccess(Void result) {
		        AppGinInjectorFactory.GIN_INJECTOR.getEventBus().fireEvent(new NotesChangeEvent());
				
			}
			@Override
			public void onFailure(Throwable caught) {
			}
		});
		
	}

}
